package com.itdct.onflow.core.scanner

import com.itdct.onflow.core.annotation.EnableTableScan
import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar
import org.springframework.core.annotation.AnnotationAttributes
import org.springframework.core.type.AnnotationMetadata


/**
 * @author Zhouwx
 * @date 2025/8/18 10:43:04
 * @version 1.0
 * @description
 */
class TableDescriptionRegistrar : ImportBeanDefinitionRegistrar {
    override fun registerBeanDefinitions(importingClassMetadata: AnnotationMetadata, registry: BeanDefinitionRegistry) {
        val scanner = TableDescriptionScanner(registry)

        val attributes = AnnotationAttributes.fromMap(
            importingClassMetadata.getAnnotationAttributes(EnableTableScan::class.java.name)
        )
        val basePackages = attributes?.getStringArray("basePackages")
        basePackages?.also {
            scanner.doScan(*it)
        }

    }
}